Here you find your exam questions. Please submit your work by commiting to github by 23:00, 7 Tuesday, latest. You can continue working on any unfinished questions and submit them until the class on Tuesday, the 14th.

Question 1

Implement a program, that, computes a moving average of a sequence $x_t$, given as a list of numbers as a list. All the boundry values should be assumed to be zero.

$$ \mu_t = \frac{1}{L}\sum_{i=0}^{L-1} x_{t-i} $$

Example:

For the list $[1,4,5,-1]$, moving average with window $L=3$ should output $[0.3333, 1.6666, 3.3333, 2.6666]$.

Then your program must plot the original sequence and the moving average. The plot should be as beautiful as possible. Demonstrate your program with a generated random walk of length $L=200$.

Question 2

Implement the Binomial options pricing model for pricing European, American and Bermudan call and put options - you can find a reference implementation on 0Wikipedia

Question 3

Read the following price data and implement a back testing program to evaluate the return for the following investment strategy:

  • Initially invest $p$ and $1-p$ percent of a total kapital $K$ to each stock respectively (microsoft and apple).

  • Every weekend, only using past averages of last two weeks, evaluate the following:

    If both stocks lost in value, or both stocks gain in value, do nothing

    Otherwise sell $r$ percent of the loosing stock with the opening price and invest the money immediately in the winning stock.

Plot the evolution of the capital and compare with the return of the static strategy where you rebalance every week to keep the $p$ - $1-p$ portfolio. Ignore any transaction fees.

Read some example Data


In [1]:
import pandas as pd

import numpy as np
import datetime

msft = pd.read_csv("msft.csv", index_col=0, parse_dates=True)
aapl = pd.read_csv("aapl.csv", index_col=0, parse_dates=True)

In [11]:
msft['2012-01']


Out[11]:
Open High Low Close Volume AdjClose
Date
2012-01-03 26.549999 26.959999 26.389999 26.770000 64731500 23.461752
2012-01-04 26.820000 27.469999 26.780001 27.400000 80516100 24.013895
2012-01-05 27.379999 27.730000 27.290001 27.680000 56081400 24.259293
2012-01-06 27.530001 28.190001 27.530001 28.110001 99455500 24.636154
2012-01-09 28.049999 28.100000 27.719999 27.740000 59706800 24.311878
2012-01-10 27.930000 28.150000 27.750000 27.840000 60014400 24.399520
2012-01-11 27.430000 27.980000 27.370001 27.719999 65582400 24.294349
2012-01-12 27.870001 28.020000 27.650000 28.000000 49370800 24.539747
2012-01-13 27.930000 28.250000 27.790001 28.250000 60196100 24.758852
2012-01-17 28.400000 28.650000 28.170000 28.260000 72395300 24.767617
2012-01-18 28.309999 28.400000 27.969999 28.230000 64860600 24.741323
2012-01-19 28.160000 28.440001 28.030001 28.120001 74053500 24.644918
2012-01-20 28.820000 29.740000 28.750000 29.709999 165902900 26.038424
2012-01-23 29.549999 29.950001 29.350000 29.730000 76078100 26.055953
2012-01-24 29.469999 29.570000 29.180000 29.340000 51703300 25.714150
2012-01-25 29.070000 29.650000 29.070000 29.559999 59231700 25.906961
2012-01-26 29.610001 29.700001 29.400000 29.500000 49102800 25.854377
2012-01-27 29.450001 29.530001 29.170000 29.230000 44187700 25.617743
2012-01-30 28.969999 29.620001 28.830000 29.610001 51114800 25.950783
2012-01-31 29.660000 29.700001 29.230000 29.530001 50572400 25.880670

In [6]:
%matplotlib inline
import matplotlib as mpl
import matplotlib.pyplot as plt
import numpy as np

plt.plot(aapl['2012']['Open'])


Out[6]:
[<matplotlib.lines.Line2D at 0x11da78490>]

In [ ]:
%matplotlib inline